package com.wxx;

/**
 * @author: Jetwang
 * @date: 2022/3/27 21:48
 * @description: ArrayQueue 队列实现类
 * @version: 1.0
 */
public class ArrayQueue<T> implements Queue<T>{

    private GenericArray<T> array;

    public ArrayQueue(int capacity) {
        array = new GenericArray<>(capacity);
    }

    public ArrayQueue() {
        array = new GenericArray<>();
    }

    @Override
    public int getSize() {
        return array.getSize();
    }

    @Override
    public boolean isEmpty() {
        return array.isEmpty();
    }

    @Override
    public void enqueue(T t) {
        array.addLast(t);
    }

    @Override
    public T dequeue() {
        return array.removeFirst();
    }

    @Override
    public T getFront() {
        return array.getFirst();
    }

    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();
        builder.append("Queue:");
        builder.append("front [");
        for (int i = 0; i < array.getSize(); i++) {
            builder.append(array.get(i));
            if (i != array.getSize()-1) {
                builder.append(",");
            }
        }
        builder.append("] tail");
        return builder.toString();
    }
}
